package mortal.game.resource.info
{
	import Message.Public.*;
	import com.gengine.utils.*;
	import com.mui.serialization.json.*;
	import mortal.game.cache.*;
	import mortal.game.model.*;
	import mortal.game.resource.*;
	import mortal.game.view.common.tooltip.*;
	
	dynamic public class ItemData extends Object
	{
		private var _data:SPlayerItem;
		private var _itemInfo:ItemInfo;
		private var _itemExInfo:Object;
		public var effectName:String;
		private var _cdTime:Number = -1;
		public var additionalInfo:Object;
		private var _propertys:Array;
		public static const nullItemData:ItemData = new ItemData(null);
		public static const ToolTipType_Pack:int = 0;
		public static const ToolTipType_Mounts:int = 1;
		public static const ToolTipType_Player:int = 2;
		public static const ToolTipType_Forge:int = 3;
		public static const ToolTipType_Exchange:int = 4;
		
		public function ItemData(param1:*)
		{
			var _loc_2:SPlayerItem = null;
			this._data = new SPlayerItem();
			this._propertys = [{property:"bind", value:0}, {property:"prefix", value:0}, {property:"hole1", value:0}, {property:"hole2", value:0}, {property:"hole3", value:0}, {property:"strengthen", value:0}, {property:"totalStrengthen", value:0}, {property:"currentStrengthen", value:0}, {property:"perfectStrengthen", value:0}, {property:"cur_strthen", value:0}, {property:"addition1", value:0}, {property:"addition2", value:0}, {property:"addition3", value:0}, {property:"addition4", value:0}, {property:"addition5", value:0}, {property:"addition6", value:0}, {property:"addStar1", value:0}, {property:"addStar2", value:0}, {property:"addStar3", value:0}, {property:"addStar4", value:0}, {property:"addStar5", value:0}, {property:"addStar6", value:0}, {property:"new_add", value:""}, {property:"new_star", value:""}, {property:"addVal1", value:0}, {property:"addVal2", value:0}, {property:"addVal3", value:0}, {property:"addVal4", value:0}, {property:"addVal5", value:0}, {property:"addVal6", value:0}, {property:"ref_count", value:0}, {property:"refine", value:0}, {property:"totalRefine", value:0}, {property:"currentRefine", value:0}, {property:"perfectRefine", value:0}, {property:"hide", value:0}, {property:"durable", value:1}];
			if (param1 is SPlayerItem)
			{
				this.data = param1;
			}
			else if (param1 is int)
			{
				_loc_2 = new SPlayerItem();
				_loc_2.itemCode = param1;
				this.data = _loc_2;
			}
			
		}
		
		public function get cdTime() : Number
		{
			if (this._cdTime < 0)
			{
				if (this._itemInfo)
				{
					this._cdTime = this._itemInfo.item.cdTime;
				}
			}
			return this._cdTime;
		}
		
		public function set cdTime(param1:Number) : void
		{
			this._cdTime = param1;
			
		}
		
		public function get uid() : String
		{
			if (this._data)
			{
				return this._data.uid;
			}
			return null;
		}
		
		public function set uid(param1:String) : void
		{
			this._data.uid = param1;
			
		}
		
		public function get itemAmount() : int
		{
			if (this._data)
			{
				return this._data.itemAmount;
			}
			return -1;
		}
		
		public function set itemAmount(param1:int) : void
		{
			this._data.itemAmount = param1;
			
		}
		
		public function get itemCode() : int
		{
			if (this._data)
			{
				return this._data.itemCode;
			}
			return -1;
		}
		
		public function get posType() : int
		{
			if (this._data)
			{
				return this._data.posType;
			}
			return -1;
		}
		
		public function set posType(param1:int) : void
		{
			if (this._data)
			{
				this._data.posType = param1;
			}
			
		}
		
		public function get playerId() : int
		{
			if (this._data)
			{
				return this._data.playerId;
			}
			return -1;
		}
		
		public function get itemInfo() : ItemInfo
		{
			return this._itemInfo;
		}
		
		public function get itemExInfo() : Object
		{
			return this._itemExInfo;
		}
		
		public function set itemExInfo(param1:Object) : void
		{
			if (param1)
			{
				this.writeDefaultProperty(param1);
			}
			this._itemExInfo = param1;
			
		}
		
		public function get data() : SPlayerItem
		{
			return this._data;
		}
		
		public function set data(param1:SPlayerItem) : void
		{
			/*
			this._data = param1;
			if (this._data)
			{
				this._itemInfo = ItemConfig.instance.getInfoByCode(this._data.itemCode);
				if (this._data.jsStr != "")
				{
					this.itemExInfo = JSON.deserialize(this._data.jsStr);
				}
				else
				{
					this.itemExInfo = null;
				}
			}
			*/
		}
		
		public function get color() : int
		{
			if (this.itemInfo)
			{
				return this.itemInfo.item.color;
			}
			return -1;
		}
		
		public function get type() : int
		{
			if (this.itemInfo)
			{
				return this.itemInfo.item.type;
			}
			return -1;
		}
		
		public function get category() : int
		{
			if (this.itemInfo)
			{
				return this.itemInfo.item.category;
			}
			return -1;
		}
		
		public function getToolTipData(param1:int = 0):*
		{
			var _loc_2:Array = null;
			var _loc_3:EquipmentToolTipData = null;
			var _loc_4:EquipmentToolTipData = null;
			var _loc_5:EquipmentToolTipData = null;
			switch(param1)
			{
				case ToolTipType_Pack:
				{
					if (this.itemInfo.item.category == ECategory._ECategoryMount)
					{
						return new ToolTipInfo(Tooltip.ToolTipRenderType_Mounts, this);
					}
					if (this.itemInfo.item.category == ECategory._ECategoryEquip || this.itemInfo.item.category == ECategory._ECategoryMagicEquip)
					{
						//_loc_2 = Cache.instance.pack.rolePackCache.getAllItems();
						_loc_3 = new EquipmentToolTipData(this, _loc_2, true);
						return new ToolTipInfo(Tooltip.ToolTipRenderType_Equipment, _loc_3);
					}
					return new ToolTipInfo(Tooltip.ToolTipRenderType_Item, this);
				}
				case ItemData.ToolTipType_Mounts:
				{
					return new ToolTipInfo(Tooltip.ToolTipRenderType_Mounts, this);
				}
				case ToolTipType_Player:
				{
					return new ToolTipInfo(Tooltip.ToolTipRenderType_Equipment, this);
				}
				case ToolTipType_Forge:
				{
					if (this.itemInfo.item.category == ECategory._ECategoryEquip || this.itemInfo.item.category == ECategory._ECategoryMagicEquip)
					{
						//_loc_2 = Cache.instance.pack.rolePackCache.getAllItems();
						_loc_4 = new EquipmentToolTipData(this, _loc_2, false, false);
						if (_loc_4.isEquiped())
						{
							_loc_4.isShowEquipped = true;
						}
						return new ToolTipInfo(Tooltip.ToolTipRenderType_Equipment, _loc_4);
					}
					else
					{
						return new ToolTipInfo(Tooltip.ToolTipRenderType_Item, this);
					}
				}
				case ToolTipType_Exchange:
				{
					if (this.itemInfo.item.category == ECategory._ECategoryEquip || this.itemInfo.item.category == ECategory._ECategoryMagicEquip)
					{
						//_loc_2 = Cache.instance.pack.rolePackCache.getAllItems();
						_loc_5 = new EquipmentToolTipData(this, _loc_2, true);
						_loc_5.additionalInfo = this.additionalInfo;
						return new ToolTipInfo(Tooltip.ToolTipRenderType_Equipment, _loc_5);
					}
					return new ToolTipInfo(Tooltip.ToolTipRenderType_Item, this);
				}
				default:
				{
					if (this.itemInfo.item.category == ECategory._ECategoryEquip || this.itemInfo.item.category == ECategory._ECategoryMagicEquip)
					{
						//_loc_2 = Cache.instance.pack.rolePackCache.getAllItems();
						return new ToolTipInfo(Tooltip.ToolTipRenderType_Equipment, new EquipmentToolTipData(this, _loc_2));
					}
					return new ToolTipInfo(Tooltip.ToolTipRenderType_Item, this);
					break;
				}
			}
		}
		
		public function getPackToolTip() : String
		{
			return [this.getNameTip(), this.getCategoryTip(), this.getTypeTip(), this.getCodeTip(), this.getIconTip(), this.getBindTip()].join("");
		}
		
		public function getMountTooltip() : String
		{
			return [this.getNameTip(), this.getCategoryTip(), this.getTypeTip(), this.getCodeTip(), this.getIconTip(), this.getBindTip()].join("");
		}
		
		private function getColorInfo() : ColorInfo
		{
			return ColorConfig.instance.getItemColor(this.itemInfo.item.color);
		}
		
		private function getNameTip() : String
		{
			return HTMLUtil.addColor(this.itemInfo.item.name, this.getColorInfo().color) + "\r";
		}
		
		private function getCategoryTip() : String
		{
			return HTMLUtil.addColor("大类：" + this.itemInfo.item.category, "#00FF00") + "\r";
		}
		
		private function getTypeTip() : String
		{
			return HTMLUtil.addColor("小类：" + this.itemInfo.item.type, "#FFFFFF") + "\r";
		}
		
		private function getCodeTip() : String
		{
			return HTMLUtil.addColor("Code:" + this.itemInfo.item.code, "#FFFFFF") + "\r";
		}
		
		private function getIconTip() : String
		{
			return HTMLUtil.addColor("Icon:" + this.itemInfo.item.icon, "#FFFFFF") + "\r";
		}
		
		private function getBindTip() : String
		{
			/*
			switch(this.itemInfo.item.bind)
			{
				case EBind._EBindAfterUse:
				{
					return HTMLUtil.addColor("玩家使用后绑定", "#006600") + "\r";
				}
				case EBind._EBindYes:
				{
					return HTMLUtil.addColor("已经绑定", "#00FF00") + "\r";
				}
				case EBind.EBindNo:
				{
					return HTMLUtil.addColor("未绑定", "#444444") + "\r";
				}
				default:
				{
					return HTMLUtil.addColor("未绑定", "#444444") + "\r";
					break;
				}
			}
			*/
			
			return '';
		}
		
		public function isSameItem(param1:ItemData) : Boolean
		{
			return param1.category == this.category && param1.type == this.type;
		}
		
		public function isCanCD() : Boolean
		{
			//return this.category == ECategory._ECategoryDrug && this.effect >= 0 && this.effect <= 2 || this.category == ECategory._ECategoryProp && this.type == EProp._EPropPassToCity;
			return false;
		}
		
		public function get effect() : int
		{
			if (this.itemInfo)
			{
				return this.itemInfo.item.effect;
			}
			return -1;
		}
		
		private function writeDefaultProperty(param1:Object) : void
		{
			var _loc_2:Object = null;
			for each (_loc_2 in this._propertys)
			{
				
				if (!param1.hasOwnProperty(_loc_2["property"]) || param1[_loc_2["property"]] == null)
				{
					param1[_loc_2["property"]] = _loc_2["value"];
				}
			}
			
		}
		
	}
}